package com.mavenq.fly.test;


import java.util.Objects;

/**
 * 每天时间列表
 */
public enum Times {
    ONE(1, "00:00"),
    TWO(2, "00:30"),
    THREE(3, "01:00"),
    FOUR(4, "01:30"),
    FIVE(5, "02:00"),
    SIX(6, "02:30"),
    SEVEN(7, "03:00"),
    EIGHT(8, "03:30"),
    NINE(9, "04:00"),
    TEN(10, "04:30"),
    ELEVEN(11, "05:00"),
    TWELVE(12, "05:30"),
    THIRTEEN(13, "06:00"),
    FOURTEEN(14, "06:30"),
    FIFTEEN(15, "07:00"),
    SIXTEEN(16, "07:30"),
    SEVENTEEN(17, "08:00"),
    EIGHTEEN(18, "08:30"),
    NINETEEN(19, "09:00"),
    TWENTY(20, "09:30"),
    TWENTY_ONE(21, "10:00"),
    TWENTY_TWO(22, "10:30"),
    TWENTY_THREE(23, "11:00"),
    TWENTY_FOUR(24, "11:30"),
    TWENTY_FIVE(25, "12:00"),
    TWENTY_SIX(26, "12:30"),
    TWENTY_SEVEN(27, "13:00"),
    TWENTY_EIGHT(28, "13:30"),
    TWENTY_NINE(29, "14:00"),
    THIRTY(30, "14:30"),
    THIRTY_ONE(31, "15:00"),
    THIRTY_TWO(32, "15:30"),
    THIRTY_THREE(33, "16:00"),
    THIRTY_FOUR(34, "16:30"),
    THIRTY_FIVE(35, "17:00"),
    THIRTY_SIX(36, "17:30"),
    THIRTY_SEVEN(37, "18:00"),
    THIRTY_EIGHT(38, "18:30"),
    THIRTY_NINE(39, "19:00"),
    FORTY(40, "19:30"),
    FORTY_ONE(41, "20:00"),
    FORTY_TWO(42, "20:30"),
    FORTY_THREE(43, "21:00"),
    FORTY_FOUR(44, "21:30"),
    FORTY_FIVE(45, "22:00"),
    FORTY_SIX(46, "22:30"),
    FORTY_SEVEN(47, "23:00"),
    FORTY_EIGHT(48, "23:30"),
    FORTY_NINE(49, "24:00");

    private Integer code;
    private String value;

    Times(Integer code, String value) {
        this.code = code;
        this.value = value;
    }
    public String getValue() {
        return value;
    }
    /**
     * 转换成毫秒
     */
    public static int timeToMill(String time) {
        String[] split = time.split(":");
        int hour = Integer.parseInt(split[0]);
        int minute = Integer.parseInt(split[1]);
        return hour * 60 * 60 * 1000 + minute * 60 * 1000;
    }

    /**
     * 判断时间格式是否正确
     */
    public static boolean isMatchTimeRule(String timeStr){
        for (Times times : Times.values()) {
            if(Objects.equals(times.getValue(), timeStr)){
                return true;
            }
        }
        return false;
    }

}